package com.group.attendance;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.sql.DataSource;

public class WeekDAO {

	Connection conn = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	DataSource ds = null;
	
	public WeekDAO() {
		try {
			//	pooling 처리 : dbcp
			Context context = new InitialContext();
			ds = (DataSource)context.lookup("java:comp/env/jdbc/Oracle10g");
		} catch (Exception e) {
			System.out.println("연결 오류:" + e.getMessage());
			return;
		}
	}
	//출근시간 표시
	public ArrayList<WeekBean> getData(){
		ArrayList<WeekBean> list = new ArrayList<>();
		try {
			conn = ds.getConnection();
			String sql ="select name,check_in,check_out From EMP_INF";
			pstmt = conn.prepareStatement(sql);
			rs = pstmt.executeQuery();
			
			while(rs.next()){
				WeekBean bean = new WeekBean();
				
				bean.setName(rs.getString("name"));
				bean.setCheck_in(rs.getString("check_in"));
				bean.setCheck_out(rs.getString("check_out"));
				
				list.add(bean);
			}
		}catch(Exception e){
			System.out.println("getData 오류 : " + e.getMessage());
		}finally{
			try{				
				if(pstmt != null)pstmt.close();	
				if(conn != null)conn.close();
			}catch(Exception e){

			}
		}
		return list;
}
}